--[[
Author: your name
Date: 2020-12-23 18:22:28
LastEditTime: 2020-12-25 15:49:59
LastEditors: your name
Description: In User Settings Edit
FilePath: \Lua\View\PopUI\UIHeroHandBookItem.lua
--]]
---@class UIHeroHandbookItem
UIHeroHandbookItem = Class("UIHeroHandbookItem",UIComponentInterface)
local t = UIHeroHandbookItem

local qualityToBgName = {"Bbg_green_quality","Bbg_blue_quality","Bbg_purple_quality","Bbg_yellow_quality"};

---@param obj FairyGUI.GComponent
function t:OnCreate(obj)
    self.bind = {}
    self.index = 0
    if obj == nil then
        logError("obj is nil ,bind failed--------------")
        return
    end
    self.bind.obj = obj
    self.bind.body = obj:GetChild("img_body")
    self.bind.type = obj:GetChild("img_type")
    self.bind.qualityBg = obj:GetChild("qualityBg")
    self.bind.RedDots = obj:GetChild("RedDots")
    self.bind.obj.onClick:Add(self.onClickHero,self)

end
function t:SetVisible(visible)
    self.bind.obj.visible = visible
end
---@return FairyGUI.GComponent
function t:GetObj()
    return self.bind.obj
end
function t:Refresh(data,index,clickCallback)
    self.data = data
    self.callback = clickCallback
    self:RemoveRedDots()
    self.index = index
    --data["herodata"] = herodata;
    --LuaBehaviour:RemoveClick(data["go"]);
    --LuaBehaviour:AddClick(data["go"],this.onClickHeroPos,herodata.f_HeroID);
    self.bind.body.url = EnumConst.AtlasPath.HalfBodyAtlas..HeroManager.GetHeroBIcon(self.data.f_HeroID)
    self.bind.type.url = EnumConst.AtlasPath.ICONAtlas..EnumConst.HeroTypeIcon[self.data.f_HeroType]
    if logicMgr.HeroManager.getHandbookByModelId(tostring(self.data.f_HeroID),true)~=nil then
        self.bind.obj.grayed = false
    else
        self.bind.obj.grayed = true
    end

    local quality = logicMgr.HeroManager.starToQuality(self.data.f_HeroInitialStar);
    --[[local colorStr = nil;
    if quality>#Config.QualityColor then
        colorStr = Config.QualityColor[#Config.QualityColor];
    elseif quality<1 then
        colorStr = Config.QualityColor[1];
    else
        colorStr = Config.QualityColor[quality];
    end]]
    if quality > #qualityToBgName then
        quality = #qualityToBgName
    end
    self.bind.qualityBg.url = EnumConst.AtlasPath.ICONAtlas..qualityToBgName[quality]
end
function t:RemoveRedDots()
    self.index = 0
end
function t:OnDestroy()
    self.data = nil
    if self.bind.obj then
        self.bind.obj.onClick:Clear()
    end
    self.callback = nil
    self:RemoveRedDots()
    table.clear(self.bind)
end
function t:onClickHero()
    if self.callback then
        self.callback(self.data.f_HeroID)
    end
end
return UIHeroHandbookItem